<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码</label>
                    <div class="layui-input-block">
                        <input type="password" id="password" name="password" value="" lay-verify="title" autocomplete="off" placeholder="请输入新密码" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">确认密码</label>
                    <div class="layui-input-block">
                        <input type="password" id="password2"  name="password2" lay-verify="title" autocomplete="off" placeholder="请输入确认密码" class="layui-input">
                    </div>
                </div>
                
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="__STATIC__/lib/layui/layui.js"></script>
<script src="__PEAR__/component/pear/pear.js"></script>
<script>
layui.use(['form','jquery'],function(){
    let form = layui.form;
    let $ = layui.jquery;

    form.on('submit(user-save)', function(data){
    	var password=$("#password").val();
		   var password2=$("#password2").val();

		   if(password==''){
		     layer.msg('新密码不能为空');
			 return false;
		   }
		   if(password2==''){
		     layer.msg('确认密码不能为空');
			 return false;
		   }
		  
		  if(password!=password2){
		   	layer.msg('两次输入密码不相同');
			 return false;
		  }
		   //提交添加
		   $.ajax({
	            type: "POST",
	            cache: false,
	            url: "{:U('Main/updatePassword')}",
	            dataType: "json",
				data:{"password":password,"password2":password2},
	            async: false,
	            success: function(data) {
	               if(data.code=='-1'){
	            	   parent.layer.msg('更新失败,请重试');
	               }
	               else if(data.code=='1'){
	            	 parent.layer.closeAll();
	              	 parent.layer.msg('更新成功');
	               }
	            }
	        });
    });
})
</script>
<script>
</script>
</body>
</html>
